package com.woniuxy.demo.contorller;

import com.woniuxy.demo.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;

/**
 * @author 佘赛飞
 * @create 2021 -10 -09 5:43 PM
 */
@RestController
@Controller
public class MyContorller {
    @PostMapping("/upload")
    public String upload(MultipartFile img) throws IOException {
        String originalFilename = img.getOriginalFilename();
        File file = new File("/Users/shesaifei/IdeaProjects/images", originalFilename);
        img.transferTo(file);
        return "ok";
    }

    @RequestMapping("/login")
    public String login(String username,String password){
        System.out.println("username"+username);
        System.out.println("password"+password);
        return "login ok";
    }
    @PostMapping("/login2")
    public String login2(@RequestBody User user, HttpSession session){
        System.out.println(session.getId());
        System.out.println("user:"+user);
        return "login2 ok";
    }
}
